##################################################################################################################################
#
# Copyright (C) 2008-2012 Mind System Connection. Lda. Part of Daidze Software, created by Siqsuruq. All other rights reserved.
#
# Mind System Connection Webpage: www.msysc.org
# Daidze Software Page: www.daidze.com www.daidze.org
# E-mail: admin@msysc.org, siqsuruq@gmail.com
#
##################################################################################################################################

proc date {} {
	set systemTime [clock seconds]
	set today [clock format $systemTime -format {%Y-%m-%d}]
	return $today
}

proc time {} {
	set systemTime [clock seconds]
	set now_time [clock format $systemTime -format {%H:%M:%S}]
	return $now_time
}

proc time_hm {} {
	set systemTime [clock seconds]
	set now_time [clock format $systemTime -format {%H:%M}]
	return $now_time
}

proc now_date_time {} {
	set systemTime [clock seconds]
	return [clock format $systemTime -format %Y-%m-%d_%H-%M-%S]
}

proc months {days} {
	set month 30.4
	set result [expr {round($days / $month)}]
	return $result
}

proc now_date {what} {
	set systemTime [clock seconds]
	if {$what == "year"} {
		return [clock format $systemTime -format "%Y"]
	}
}

proc every {ms body} {
	eval $body
	after $ms [list every $ms $body]
}

# Compare 2 dates and return earlier date first
proc compare_dates {date1 date2} {
	set d1 [clock scan "$date1"]
	set d2 [clock scan "$date2"]
	if { [expr { $date1 < $date2 }] } {
		return [list $date1 $date2]
	} else {
		return [list $date2 $date1]
	}
}